import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;


public class EIBezeroaKontsultatu extends JFrame {

	private JPanel contentPane;
	private JTextField nanSartu;
	private JButton bilatu;
	private JButton atzera;
	private JButton logout;
	private Taula taula;
	private JButton bezeroaEzabatu;


	public EIBezeroaKontsultatu() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		setVisible(true);
		elementuakHasieratu();
		botoiakHasieratu();
		
	}
	
	public void elementuakHasieratu(){

		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblTerapeutarenNan = new JLabel("Bezeroaren nan:");
		lblTerapeutarenNan.setBounds(257, 42, 147, 15);
		contentPane.add(lblTerapeutarenNan);
		
		nanSartu = new JTextField();
		nanSartu.setBounds(415, 40, 114, 19);
		contentPane.add(nanSartu);
		nanSartu.setColumns(10);
		
		bilatu = new JButton("Bilatu");
		bilatu.setBounds(559, 37, 117, 25);
		contentPane.add(bilatu);
		
		logout = new JButton("Logout");
		logout.setBounds(796, 12, 84, 25);
		contentPane.add(logout);
		
		atzera = new JButton("Atzera");
		atzera.setBounds(796, 515, 84, 25);
		contentPane.add(atzera);
		
		Vector<String> izenak = new Vector<String>();
		izenak.addElement("NAN");
		izenak.addElement("Izena");
		izenak.addElement("Abizena");
		izenak.addElement("Telefonoa");
		izenak.addElement("Helbidea");
		taula = new Taula(izenak);
		taula.setBounds(177, 112, 579, 317);
		contentPane.add(taula);
		
		bezeroaEzabatu = new JButton("Bezeroa ezabatu");
		bezeroaEzabatu.setBounds(380, 441, 185, 25);
		contentPane.add(bezeroaEzabatu);
	}
	
	public void botoiakHasieratu(){
		bilatu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Bezeroa b = BezeroKudeatzailea.getInstantzia().bezeroaKontsultatu(nanSartu.getText());
				pantailaratu(b);
			}
		});
		
		bezeroaEzabatu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				BezeroKudeatzailea.getInstantzia().bezeroaEzabatu(nanSartu.getText());
			
			}
		});
		
		
		atzera.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//EIIdazkari frame = new EIIdazkari();
				EIBezeroKudeatzailea frame = new EIBezeroKudeatzailea();
				EIBezeroaKontsultatu.this.dispose();
			}
		});
		
		logout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				EILogin frame = new EILogin();
				EIBezeroaKontsultatu.this.dispose();
			}
		});
	}
	public void pantailaratu(Bezeroa b){	
					
			
			taula.lerroaGehitu(b);
			
		
	}
}
